package Message;

import java.io.IOException;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import OCSF.ConnectionToClient;
import Server.SQLConnection;

public class MessageOneTimeRequest extends Message{
	
	public  MessageOneTimeRequest(String[] str, ConnectionToClient client)
	{
		super(str,client);
	}
	public void execute() throws SQLException, IOException
	{
		
		PreparedStatement ps2=conn.getConnection().prepareStatement("INSERT INTO test.parkingorder (idParkingOrder,vehicleNum,idParkingLot,startDate,endDate,startTime,endTime,price) VALUES(?,?,?,?,?,?,?,?);");
	    PreparedStatement ps3=conn.getConnection().prepareStatement("SELECT * FROM test.parkingorder;");
	    ResultSet rs=ps3.executeQuery();
	    int row=0;
	    while(rs.next())
	    {
	    	int temp=rs.getInt(1);
	    	if(row<temp)
	    		row=temp;
	    }
	    
	    ps2.setInt(1, row+1);
	    ps2.setString(2,str[1]);
	    ps2.setString(3,str[2]);
	    ps2.setString(4,str[3]);
	    ps2.setString(5,str[4]);
	    ps2.setString(6,str[5]);
	    ps2.setString(7,str[6]);
	    ps2.setString(8,"100");
	     ps2.executeUpdate();
	    ps3.close();
	    rs.close();
	    
	    client.sendToClient("OneTimeRequest");
	}
}
